#pragma once

#include <iostream>
#include <memory>
#include <string>
#include <sstream>
#include <jsoncpp/json/json.h>
#include <jsoncpp/json/writer.h>  
#include <unordered_map>
#include <fstream>
#include<filesystem>
namespace ns_http{
    //调用
    struct Contentmap{

    static void Init()
    {
        if(_Cont_type.empty())
        {
            std::ifstream ifs("Content-type.conf");
            std::string subfix;
            std::string type;
            while(!ifs.eof())
            {
                ifs>>subfix;
                if(subfix.find(".") == std::string::npos) break;
                ifs>>type;
                _Cont_type[subfix] = type;
            }
            ifs.close();
        }
    }
    static std::string sub_type(const std::string & subfix)
    {
        std::string s = _Cont_type[subfix];
        if(s.size())
            return s;
        return "text/html";
    }
    static std::unordered_map<std::string,std::string> _Cont_type;
};
std::unordered_map<std::string,std::string> Contentmap:: _Cont_type;

struct Status_code_Desc{
    static void Init()
    {
        if(_code_Desc.empty())
        {
            std::ifstream ifs("status_code.conf");
            if(!ifs.is_open())
            {
                return ;
            }
            std::string code;
            std::string en_desc;
            std::string zh_desc;
            while(!ifs.eof())
            {
                ifs>>code;
                ifs>>en_desc;
                ifs>>zh_desc;
                _code_Desc[code] = en_desc +" "+ zh_desc;
            }
        }
    }
    static std::string Code_desc(int code)
    {
        return Code_desc(std::to_string(code));
    }
    static std::string Code_desc(std::string code)
    {
        return _code_Desc[code];
    }
    static std::unordered_map<std::string,std::string> _code_Desc;
};

std::unordered_map<std::string,std::string> Status_code_Desc::_code_Desc;
};